<template>
	<view class="data-stat"
		:style="{ background: `url(${assetsPath}cf956855eabdd169264a8a8c6b89d037f5228169.png) left top/100% calc(${navBarHeight}px + 280rpx) no-repeat` }">
		<nav-bar title="财务收入" :color="navBarColor" :bg="navBarBg" />

		<view class="address">
			<view class="flex-space-between">
				<view class="flex-align">
					<van-image v-if="itemChooselist.venue_thumb != ''" width="74rpx" height="74rpx" radius="2"
						style="margin-right: 10rpx;" :src="itemChooselist.venue_thumb" />
					<van-image v-else width="74rpx" height="74rpx" radius="10rpx" fit="cover" style="margin-right: 10rpx;" src="https://img.yzcdn.cn/vant/cat.jpeg" />
					<view>
						<view class="address-name">{{itemChooselist.venue_name}}</view>
						<view class="address-desc">地址:{{itemChooselist.address}}</view>
					</view>
				</view>
				<view class="exchange flex-center flex-column " @click="show_no">
					<van-icon name="exchange" size="16" />
					切换
				</view>
			</view>
		</view>

		<view class="data-stat-wrapper">
			<view class="dates d-flex">
				<view v-for="item in dates" :key="item.value" @click="dataslist(item)" class="date-item flex-center"
					:class="{ active: dateActive === item.value }">
					{{ item.label }}
				</view>
			</view>

			<view class="data-wrapper">
				<!-- <view class="date">5月8日</view> -->
				<van-row class="text-center">
					<van-col :span="12">
						<view class="value">{{income}}</view>
						<view class="label">实收金额</view>
					</van-col>
					<van-col :span="12">
						<view class="value">{{order_cnt}}</view>
						<view class="label">订单数(笔)</view>
					</van-col>
					<!-- <van-col :span="8">
						<view class="value">302</view>
						<view class="label">新增用户(人)</view>
					</van-col> -->
				</van-row>
			</view>
		</view>
		<view style="width: 100%; height: 60rpx;background-color: #f8f8f8;margin-top: 20rpx;">
			<view style="float: left;">
				<image style="width: 32rpx;height: 32rpx;margin-top: 15rpx;margin-left: 30rpx;"
					src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/dbe7a7371520f7585b4a83558336c24acbace2cc.png"
					mode=""></image>
			</view>
			<view style="float: left;line-height: 60rpx;font-size: 28rpx;color: #aaaaaa;margin-left: 20rpx;">
				数据仅供参考，以后台财务数据为准
			</view>
		</view>
		<view class="title">收入趋势</view>
		<view v-show="showlist">
			<!-- <qiun-data-charts type="line" :opts="opts" :chartData="chartData" /> -->
			<qiun-data-charts type="line" canvasId="scrolllineid"
				:opts="{enableScroll:true,xAxis:{scrollShow:true,itemCount:4,disableGrid:true}}" :chartData="chartData"
				:ontouch="true" :canvas2d="true" />
		</view>
		<view class="title1 flex-space-between">
			<view class="title">销售额分析</view>
			<!-- <view class="date">2020.01.01~08.03</view> -->
		</view>

		<view v-show="showlist">
			<!-- <qiun-data-charts type="ring" :opts="ringopts" :chartData="pieChartData" /> -->
			<qiun-data-charts type="ring" :opts="pieOpts" :chartData="pieChartData" />
		</view>

		<v-gap />
		<view class="title1 flex-space-between">
			<view class="title">销售额明细</view>
			<!-- <view class="date">2020.01.01~08.03</view> -->
		</view>
		<view class="table text-center">
			<view class="thead">
				<view class="tr d-flex">
					<!-- <view class="th">所属部门</view> -->
					<view class="th" style="width: 20%;">产品分类</view>
					<!-- <view class="th">产品名称</view> -->
					<view class="th" style="text-align: right;">数量</view>
					<view class="th" style="text-align: right;">应收</view>
					<view class="th" style="text-align: right;">优惠</view>
					<view class="th" style="text-align: right;">实收</view>
				</view>
			</view>
			<view class="tbody">
				<scroll-view :scroll-top="scrollTop" scroll-y="true" class="list-2">
					<view class="tr d-flex" v-for="(item, index) in tableData" :key="index">
						<!-- <view class="td ellipsis-1">{{ item.a }}</view> -->
						<view class="td ellipsis-1" style="width: 20%;">{{ item.pro_type }}</view>
						<!-- <view class="td ellipsis-1">{{ item.c }}</view> -->
						<view class="td ellipsis-1" style="text-align: right;">{{ item.goods_number }}</view>
						<view class="td ellipsis-1" style="text-align: right;">{{ item.should_income }}</view>
						<view class="td ellipsis-1" style="text-align: right;color: #ff0000;">{{ item.discount_amount }}</view>
						<view class="td ellipsis-1" style="text-align: right;">{{ item.act_income }}</view>
					</view>
				</scroll-view>
				<view class="tr flex-align " style="font-weight: 700;">
					<view class="td ellipsis-1" style="width: 20%;">合计</view>
					<!-- <view class="td ellipsis-1"></view> -->
					<!-- <view class="td ellipsis-1"></view> -->
					<view class="td ellipsis-1" style="text-align: right;">{{sum}}</view>
					<view class="td ellipsis-1" style="text-align: right;">￥{{sum1}}</view>
					<view class="td ellipsis-1 red" style="text-align: right;">￥{{sum3}}</view>
					<view class="td ellipsis-1" style="text-align: right;">￥{{sum2}}</view>
				</view>
			</view>
		</view>


		<van-popup closeable :show="show" round position="bottom" @close="showclose">
			<view class="good-box">
				<view class="title">
					切换场馆
				</view>
				<view class="good-list">
					<!-- <van-radio-group :value="radio" @change="onChange"> -->
					<view class="good-item" v-for="(item,index) in venuelist" :key="index" @click="onChangelist(item)">
						<!-- <van-radio :name="index" :value="index" color="#2f75fa"
								:checked="index == 0 ? true : false"> -->
						<view class="flex-align">
							<van-image width="124rpx" height="124rpx" radius="10rpx" fit="cover"
								v-if="item.venue_thumb != ''" :src="item.venue_thumb" />
							<van-image v-else width="124rpx" height="124rpx" radius="10rpx" fit="cover"
								src="https://img.yzcdn.cn/vant/cat.jpeg" />
							<view class="info">
								<view class="name">{{item.venue_name}}</view>
								<view class="flex-align" v-if="item.project_list != ''">
									<view class="tag" v-if="item.project_list[0].name != ''">
										{{item.project_list[0].name}}
									</view>
									<view class="tag" v-if="item.project_list[1].name != '' && item.project_list[1]">
										{{item.project_list[1].name}}
									</view>
									<view class="tag" v-if="item.project_list[2].name != ''&& item.project_list[2]">
										{{item.project_list[2].name}}
									</view>
								</view>
								<view class="address">{{item.address}}</view>
							</view>
						</view>
						<!-- </van-radio> -->
					</view>
					<!-- </van-radio-group> -->
				</view>

				<!-- 	<view class="footer">
					<view class="btn" @click="queren">确认</view>
				</view> -->
			</view>
		</van-popup>
	</view>
</template>

<script>
	const personal = require("@/api/personal/index.js");
	import navbar from '@/mixins/navbar.js';
	const venues = require("@/api/venues/venues.js");
	export default {
		mixins: [navbar({
			navBarColor: '#fff'
		})],
		data() {
			return {
				navBarHeight: 0,
				assetsPath: this.$https.assetsPath,
				show: false,
				radio: '1',
				dates: [{
						label: '今日',
						value: '5'
					},
					{
						label: '本周',
						value: '6'
					},
					{
						label: '本月',
						value: '7'
					},
					{
						label: '本年',
						value: '8'
					},
				],
				dateActive: '5',
				opts: {
					"color": ['#635df7'],
					fontSize: 12,
					"xAxis": {
						axisLineColor: 'rgb(229,229,229)',
						"disableGrid": true,
						fontColor: 'rgb(153,153,153)',
						fontSize: 10,
					},
					"yAxis": {
						gridColor: 'rgb(229,229,229)',
						data: [{
							axisLine: false,
							fontColor: 'rgb(153,153,153)',
							fontSize: 10,
							title: '收入(元)'
						}],
						showTitle: true
					},
					"legend": {
						show: false
					},
					"extra": {
						"line": {
							"type": "straight",
							"width": 2
						},
					}
				},
				// 收入趋势
				chartData: {
					categories: [],
					series: [{
						name: "",
						data: [],
						pointShape: 'none',
						textColor: 'rgba(0,0,0,0)'
					}]
				},
				// 销售额分析总额
				pieOpts: {
					"title": {
						"name": "总额",
						"fontSize": 10,
						"color": "#b5b5b5"
					},
					"subtitle": {
						"name": "￥",
						"fontSize": 10,
						"color": "#b5b5b5"
					},
					color: ['rgb(230,148,148)', 'rgb(82,222,151)', 'rgb(241,201,176)', 'rgb(81,200,194)',
						'rgb(241,237,153)', 'rgb(178,154,228)', 'rgb(245,225,153)', 'rgb(219,246,186)'
					],
					extra: {
						ring: {
							borderWidth: 1,
							ringWidth: 30,
							// linearType: 'custom',
						}
					},
					legend: {
						position: 'bottom'
					},
					// dataLabel: false,
				},

				// 销售额分析
				pieChartData: {
					series: [{
						data: [
						]
					}]
				},
				chartsDataRing1: {
					"series": [{
						"data": [{
							"name": "一班",
							"value": 50
						}, {
							"name": "二班",
				 		"value": 30
						}, {
							"name": "三班",
							"value": 20
						}, {
							"name": "四班",
							"value": 18
						}, {
				 		"name": "五班",
							"value": 8
						}]
					}]
				},
				// 销售额明细
				tableData: [],
				venuelist: [], //场馆列表
				itemChoose: {}, // 场馆数据
				itemChooselist: {}, // 场馆数据
				showlist: true,
				income: '',
				order_cnt: "",
				sum: "",
				sum1: "",
				sum2: "",
				sum3: "",
				nac: 5
			}
		},
		created() {
			const {
				navBarHeight
			} = getApp().globalData;
			this.navBarHeight = navBarHeight;

		},
		onLoad() {
			if (uni.getStorageSync("entry_name") == '') {
				uni.showToast({
					title: '请登录！',
					icon: 'exception',
					duration: 850
				});
				setTimeout(() => {
					uni.navigateTo({
						url: '/pages/my-center/my-center'
					})
				}, 1000);
			}
			var data = uni.getStorageSync("wqzdy");
			var items = JSON.parse(data)
			this.venuelist = items
			this.itemChooselist = this.venuelist[0]
			this.finance()
		},
		methods: {
			async finance() {
				// uni.showLoading({
				// 	title: "加载中",
				// 	mask: true,
				// });
				let params = {
					venue_id: this.itemChooselist.id,
					sourceTab: this.nac
				};
				let res = await personal.finance(params);
				if (res.code == 1) {
					this.chartData = res.data.chartData //收入趋势
					this.pieChartData = res.data.pieChartData //销售额分析
					this.order_cnt = res.data.incomeInfo.order_cnt //订单号
					this.income = res.data.incomeInfo.income //收入
					this.tableData = res.data.billingList //销售额明细
					this.pieOpts.subtitle.name = res.data.pieChartData.total_income
					this.sum = res.data.billingList.reduce((acc, val) => acc + parseFloat(val.goods_number), 0)
					this.sum1 = res.data.billingList.reduce((acc, val) => acc + parseFloat(val.should_income), 0)
					this.sum2 = res.data.billingList.reduce((acc, val) => acc + parseFloat(val.act_income), 0)
					this.sum3 = res.data.billingList.reduce((acc, val) => acc + parseFloat(val.discount_amount), 0)
					// uni.hideLoading();
				}
			},
			onClick({
				url
			}) {
				uni.navigateTo({
					url
				})
			},
			// 选择场馆
			onChange(e) {
				let that = this
				let i = e.detail
				const item = this.venuelist[i]
				if (item) {
					this.itemChoose = item
					this.venuelist[i].checked = true
				} else {
					this.itemChoose = {}
				}
			},
			onChangelist(item) {
				this.itemChoose = item
				this.itemChooselist = this.itemChoose
				this.show = false
				this.showlist = true
				this.nac = this.nac
				this.dateActive = this.dateActive
				this.finance()
			},
			// 确认按钮
			queren() {
				this.itemChooselist = this.itemChoose
				this.show = false
				this.showlist = true
				this.nac = this.nac
				this.dateActive = this.dateActive
				this.finance()
			},
			dataslist(item) {
				this.chartData = [] //收入趋势
				this.pieChartData = [] //销售额分析
				this.order_cnt = [] //订单号
				this.income = [] //收入
				this.tableData = [] //销售额明细
				this.sum = ''
				this.sum1 = ''
				this.sum2 = ''
				this.sum3 = ''
				this.nac = item.value
				this.dateActive = item.value
				this.finance()
			},
			show_no() {
				this.show = true
				this.showlist = false
			},
			showclose() {
				this.show = false
				this.showlist = true
			}
		},

	}
</script>

<style lang="scss" scoped>
	.data-stat {
		min-height: 100vh;
		padding: 0 36rpx 50rpx;

		.title1 {
			padding: 30rpx;
			font-weight: 700;

			.title {
				font-size: 30rpx;
			}

			.date {
				font-size: 24rpx;
				color: #bebebe;
			}
		}

		.table {
			line-height: 70rpx;
			font-size: 22rpx;

			.thead {
				background-color: rgb(248, 248, 248);
				color: rgb(153, 153, 153);
			}

			.tbody {
				// font-weight: 700;

				.list-2 {
					width: 100%;
					max-height: 500rpx;

					// background-color: aqua;
					.tr {
						&:nth-of-type(2n) {
							background-color: rgb(248, 248, 248);
						}
					}
				}
			}


			.th,
			.td {
				width: 23%;
				text-align: left;
				height: 70rpx;

				&:nth-of-type(2) {
					width: 15%;
				}
			}
		}

		.address {
			color: #fff;
			padding-top: 20rpx;
			padding-right: 30rpx;
			height: 70rpx;

			&-name {
				font-size: 34rpx;
				font-weight: 700;
				line-height: 34rpx;
			}

			&-desc {
				margin-top: 18rpx;
				font-size: 22rpx;
				line-height: 22rpx;
			}

			.exchange {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				background-color: rgba(0, 0, 0, 0.2);
				color: rgb(234, 248, 248);
				font-size: 24rpx;
			}
		}

		.data-stat-wrapper {
			margin-top: 70rpx;
			background-color: rgb(239, 238, 253);
			border-radius: 20rpx;

			.dates {
				color: rgb(99, 93, 247);
				font-size: 30rpx;
				font-weight: 500;
				height: 84rpx;

				.date-item {
					width: 25%;
					position: relative;

					&+.date-item::before {
						content: '';
						position: absolute;
						left: 0;
						top: 50%;
						background-color: rgb(99, 93, 247);
						width: 1rpx;
						height: 42rpx;
						margin-top: -21rpx;
					}

					&.active {
						background-image: url('https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61a6df60dc329c0011115679/61af0460d092020011e18206/16391227120474676593.png');
						background-size: 100% 100%;
						background-repeat: no-repeat;
						margin-top: -16rpx;
						font-size: 36rpx;
						font-weight: 700;

						&+.date-item::before {
							display: none;
						}
					}
				}
			}

			.data-wrapper {
				padding: 30rpx;

				.date {
					font-size: 26rpx;
					font-weight: 500;
					margin-bottom: 20rpx;
				}

				.value {
					color: rgb(51, 51, 51);
					font-size: 44rpx;
					font-weight: 700;
					line-height: 40rpx;
				}

				.label {
					color: rgb(51, 51, 51);
					font-size: 26rpx;
					font-weight: 500;
					line-height: 25rpx;
					margin-top: 20rpx;
				}
			}
		}

		.title {
			color: #000;
			font-size: 30rpx;
			font-weight: 700;
			margin-top: 40rpx;
		}

		.classify {
			.box {
				margin-top: 40rpx;
			}
		}

		/deep/ .good-box {
			height: 60vh;
			padding: 0px 30rpx;
			display: flex;
			flex-direction: column;

			.van-radio__label {
				line-height: inherit;
			}

			.good-list {
				flex: 1;
				height: 0;
				overflow: auto;

				.good-item {
					margin-top: 30rpx;

					.info {
						margin-left: 25rpx;

						.name {
							color: rgb(51, 51, 51);
							font-size: 30rpx;
							font-weight: 500;
							margin-bottom: 10rpx;
						}


						.tag {
							color: rgb(4, 179, 90);
							font-size: 24rpx;
							font-weight: 500;
							padding: 0px 10rpx;
							margin-right: 20rpx;
							background-color: rgba(4, 179, 90, 0.2);
							border-radius: 4rpx;

							&:nth-of-type(2) {
								color: rgb(236, 70, 246);
								background-color: rgba(236, 70, 246, 0.2);
							}
						}

						.address {
							margin-top: 10rpx;
							color: rgb(136, 136, 136);
							font-size: 22rpx;
						}
					}

				}
			}

			.footer {
				padding: 20rpx 0;
				background-color: rgb(255, 255, 255);

				.btn {
					color: rgb(255, 255, 255);
					font-size: 30rpx;
					font-weight: 700;
					padding: 20rpx 0;
					text-align: center;
					background-image: linear-gradient(0deg, rgb(99, 93, 247) 0%, rgb(165, 173, 246) 100%);
					border-radius: 60rpx;
				}
			}
		}
	}
</style>
